﻿
@{
	Layout = null;
}

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>货物退回</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="~/layuimini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
	<link href="~/layuimini/css/public.css" rel="stylesheet" />
</head>
<body>
	<div class="layuimini-container">
		<div class="layuimini-main">

			<fieldset class="table-search-fieldset">
				<legend>搜索信息</legend>
				<div style="margin: 10px 10px 10px 10px">
					<form class="layui-form layui-form-pane" action="">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">配送状态</label>
								<div class="layui-input-inline">
									<select name="State" id="statusSelect">
										<option value=""></option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
							</div>
						</div>
					</form>
				</div>
			</fieldset>

			<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                {{#  if(d.state == '待揽收'){ }}
                    <a class="layui-btn layui-btn-xs layui-btn-normal data-count-delete" lay-event="receipts">揽收</a>
                {{#  }else if(d.state == '配送中'){ }}
            <a class="layui-btn layui-btn-xs layui-btn-normal data-count-delete" lay-event="evaluate">确认送达</a>
                {{#  }else { }}
                <a class="layui-btn layui-btn-xs layui-btn-disabled">确认收货</a>
                {{#  } }}
            </script>

		</div>
	</div>
	<script src="~/layuimini/lib/layui-v2.6.3/layui.js"></script>

	<script>
        var tableIns;

        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

			//异步获取耗材下拉选数据集合
			$.ajax({
                url: 'http://localhost:31861/api/Returns/GetStatusSelectOption',
				type: 'get',
				success: function (res) {
					console.log(res);
					if (res.isSuccess) {
						if (res.datas) {
							var options = res.datas;
							//赋值下拉选
							for (var i = 0; i < options.length; i++) {
								$('#statusSelect').append('<option value="' + options[i].value + '">' + options[i].key + '</option>');
							}

							form.render('select'); //刷新select选择框渲染
						}
					}
				}
			});

            //渲染table并且获取实例
            tableIns = table.render({
                elem: '#currentTableId',
                url: 'http://localhost:31861/api/Returns/GetReturnsList',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    { type: "checkbox", width: 50 },
                    { field: 'id', title: 'ID', hide: true, sort: true },
                    { field: 'orderId', title: '订单ID', hide: true },
                    { field: 'commodityName', title: '商品名称', sort: true },
                    { field: 'userName', title: '客户名', sort: true },
                    { field: 'address', title: '配送地址', sort: true },
                    { field: 'distributionName', title: '配送员名', sort: true },
                    { field: 'state', title: '配送状态', sort: true },
					{ field: 'sendTime', title: '到仓时间', sort: true },
					{ field: 'createTime', title: '创建时间', sort: true },
                    { title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center" }
                ]],
                limits: [5, 10, 15, 20, 25, 50],
                limit: 5,
                page: true,
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);

                tableIns.reload({
                    where: { //设定异步数据接口的额外参数，任意设
						state: data.field.State
                        //…
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });

                return false;
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'receipts') {
                    layer.confirm('真的揽收么？', function (index) {
                        //发送请求，删除数据库中的用户
                        $.ajax({
                            url: '/Returns/CommBuyoff',
                            data: { 'returnsId': obj.data.id },
                            type: 'post',
                            success: function (res) {
                                if (res.isSuccess) {
                                    //刷新表格
                                    reLoadTable();
                                }

                                layer.msg(res.msg);
                            }
                        });
                        /*obj.del();*/
                        layer.close(index);
                    });
                } else if (obj.event === 'evaluate') {
                    layer.confirm('货物确认送到么？', function (index) {
                        //发送请求，删除数据库中的用户
                        $.ajax({
                            url: 'http://localhost:31861/api/Returns/BtnCommDelivery',
                            data: { 'returnsId': obj.data.id },
                            type: 'post',
                            success: function (res) {
                                if (res.isSuccess) {
                                    //刷新表格
                                    reLoadTable();
                                }

                                layer.msg(res.msg);
                            }
                        });
                        /*obj.del();*/
                        layer.close(index);
                    });
                }
            });





          
        });
        //刷新表格
        function reLoadTable() {
            tableIns.reload({
                //where: { //设定异步数据接口的额外参数，任意设
                //    aaaaaa: 'xxx'
                //    , bbb: 'yyy'
                //    //…
                //}
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        }
	</script>

</body>
</html>